package com.itqf.mybatis;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itqf.mapper.StudentMapper;
import com.itqf.mapper.UserMapper;
import com.itqf.pojo.Student;
import com.itqf.pojo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

/**
 * projectName: mybatisgp8
 *
 * @author: 赵伟风
 * time: 2021/7/29 16:42
 * description:查看properties配置是否生效
 */
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = "classpath:spring-xx.xml")
public class UseMybatis {

    @Autowired
    private StudentMapper studentMapper;

    @Autowired
    private UserMapper userMapper;

    @Test
    public void test1(){

        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("s_name", "二狗子");
        queryWrapper.or().eq("s_age", 11);


        List<Student> students = studentMapper.selectList(queryWrapper);

        System.out.println("students = " + students);


        List<User> users = userMapper.selectList(null);
        System.out.println("users = " + users);


        Page<User> page = new Page<>(1,1);

        Page<User> page1 = userMapper.selectPage(page, null);

        List<User> records = page1.getRecords();

        System.out.println("records = " + records);

        List<OrderItem> orders = page1.getOrders();

        System.out.println("orders = " + orders);

    }

}
